package a66weding.com.jiehuntong.fragment.category.adapter;

import android.content.Context;
import android.media.projection.MediaProjection;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.andview.refreshview.recyclerview.BaseRecyclerAdapter;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.beans.ShoplistBean;
import a66weding.com.jiehuntong.common.utils.ImageOptionsUtil;
import a66weding.com.jiehuntong.inner.OnItemClickLitener;
import a66weding.com.jiehuntong.view.CircleImageView;
import a66weding.com.jiehuntong.widgets.CircularImage;

/**
 * Created by admin on 2016/8/6.
 */
public class BusinessAdapter extends BaseRecyclerAdapter<BusinessAdapter.ViewHolder> {
    //如果有点击事件请设置一个监听;
    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener)
    {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    private Context context;
    private List<ShoplistBean.DataBean> data ;

    public BusinessAdapter(Context context, List<ShoplistBean.DataBean> data){
        this.context = context;
        if (data!=null){
            this.data = data;
        }else {
            this.data = new ArrayList<>();
        }

    }

    @Override
    public ViewHolder getViewHolder(View view) {
        return new ViewHolder(view);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType, boolean isItem) {
        View v =  LayoutInflater.from(context).inflate(R.layout.item_findshop_shoplist,parent, false);
        ViewHolder viewHolder = new ViewHolder(v);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position, boolean isItem) {
        if (mOnItemClickLitener!=null){
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView,pos);
                }
            });
        }
        if (data!=null){
            x.image().bind(holder.circleImageView,data.get(position).getNvc_Logo(), ImageOptionsUtil.getcircle_fixy());
            holder.tv_nvcName.setText(data.get(position).getNvc_StoreName());
          //  holder.tv_item_taocan.setText(data.get(position).get);
            //案例数
            holder.tv_examplecount.setText(""+data.get(position).getCasesCount());
            //粉丝数
            holder.tv_fensi.setText(""+data.get(position).getBusinessMemberCount());
            //
            holder.tv_item_taocan.setText(""+data.get(position).getProductCount());
        }
    }

    @Override
    public int getAdapterItemCount() {
        return data.size();
    }

    public  class ViewHolder extends RecyclerView.ViewHolder{
        private CircularImage circleImageView;
        private TextView tv_nvcName;
        private TextView tv_item_taocan;
        private TextView tv_examplecount;
        private TextView tv_fensi;
        public ViewHolder(View itemView) {
            super(itemView);
            circleImageView = (CircularImage) itemView.findViewById(R.id.iv_lable_shop);
            tv_nvcName = (TextView) itemView.findViewById(R.id.tv_nvcName);
            tv_item_taocan = (TextView) itemView.findViewById(R.id.tv_item_taocan);
            tv_examplecount = (TextView) itemView.findViewById(R.id.tv_examplecount);
            tv_fensi = (TextView) itemView.findViewById(R.id.tv_fensi);
        }
    }
    public void append(List<ShoplistBean.DataBean> data) {
        if (data.size()!=0){
            this.data.addAll(data);
        }
        notifyDataSetChanged();
    }
    public void clear() {
        this.data.clear();
    }
    public int getSize(){
        return data.size();
    }
}
